package com.oa.demo.common.configure;


import com.oa.demo.common.handler.BaseAccessDeniedHandler;
import com.oa.demo.common.handler.BaseAuthenticationEntryPoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;

/**
 * 统一权限的异常处理
 * @author 孔德成
 * @date 2020/11/24 16:47
 */
public class BaseAuthExceptionConfigure {

    /**
     * 403 权限
     * @return
     */
    @Bean
    //当IOC容器中没有指定名称或类型的Bean的时候,就注册它
    @ConditionalOnMissingBean(name = "accessDeniedHandler")
    public BaseAccessDeniedHandler accessDeniedHandler() {
        return new BaseAccessDeniedHandler();
    }

    /**
     * 401 token
     * @return
     */
    @Bean
    @ConditionalOnMissingBean(name = "authenticationEntryPoint")
    public BaseAuthenticationEntryPoint authenticationEntryPoint() {
        return new BaseAuthenticationEntryPoint();
    }

}
